package com.chengqj.order.service;

import com.chengqj.order.entity.OrderDO;
import com.chengqj.order.repository.OrderRepository;
import com.chengqj.user.entity.UserDO;
import com.chengqj.user.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Service
public class OrderService {
    /** [mongo] 用户 */
    @Autowired
    private OrderRepository orderRepository;
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 保存用户及订单数据 使用链式事务管理器
     * @param user
     */
//    @Transactional(transactionManager = "chainedTransactionManager")
    public void save(UserDO user){
        userInfoService.save(user);
        OrderDO orderDO = new OrderDO();
        orderDO.setAmount(user.getAmount());
        orderDO.setGmtCreate(LocalDateTime.now());
        orderDO.setUserId(user.getId());
        orderRepository.save(orderDO);
        throw new RuntimeException();
    }

}
